<?php
namespace app\admin\controller;

use app\admin\module\ArticleModule;
use app\admin\module\SpecModule;
use app\BaseController;
use app\common\model\SpecValue;
use app\common\validate\Spec as SpecValidate;
use app\common\validate\SpecValue as SpecValueValidate;
use app\Request;
use think\Exception;

class Spec extends BaseController {

    public function index(){
        $list = SpecModule::page();
        return $this->success('ok',$list);
    }

    public function create(Request $request){
        $post = $request->post();
        $validate = new SpecValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }
        SpecModule::create($post);
        return $this->success('ok');
    }

    public function update(Request $request){
        $post = $request->post();
        $validate = new SpecValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }
        SpecModule::update($post);
        return $this->success('ok');
    }

    public function remove(Request $request){
        $id = $request->param('id');
        SpecModule::remove($id);
        return $this->success('ok');
    }


    public function value(Request $request){
        $id = $request->param("id");
        $data = SpecModule::allVal($id);
        return $this->success('ok',$data);
    }

    public function createVal(Request $request){
        $post = $request->post();
        $validate = new SpecValueValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }
        SpecModule::createVal($post);
        return $this->success('ok');

    }

    public function updateVal(Request $request){
        $post = $request->post();
        $validate = new SpecValueValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }
        SpecModule::updateVal($post);
        return $this->success('ok');
    }

    public function removeVal(Request $request){
        $id = $request->param('id');
        SpecModule::removeVal($id);
        return $this->success('ok');
    }

}